package com.study.java8;

import java.util.function.BiFunction;
import java.util.function.Function;

/**
 * @author ysy
 * @version 1.0
 * @Title: FunctionTest
 * @Note <b>ProjectName:</b> cusc-venus
 * <br><b>PackageName:</b> com.cusc.venus.acc.center.util
 * <br><b>ClassName:</b>
 * <br><b>Date:</b>
 */
public class FunctionTest {

    public static void main(String[] args) {

        // 有输入有返回的函数式接口
        Function<Integer, Integer> function1 = e -> e * 6;
        System.out.println(function1.apply(2));

        // 默认方法compose：先执行方法参数中的apply，将结果返回调用方，继续执行apply
        function1 = e -> e * 2;
        Function<Integer, Integer> function2 = e -> e * e;
        Integer apply2 = function1.compose(function2).apply(3);
        System.out.println(apply2);

        // 【与compose执行顺序相反】默认方法andThen：先执行调用andThen函数的apply方法，然后在将执行结果传递给andThen方法after参数中的apply方法在执行
        function1 = e -> e * 2;
        function2 = e -> e * e;
        Integer apply3 = function1.andThen(function2).apply(3);
        System.out.println(apply3);

        // 默认方法identity：输入什么返回结果就是什么 （用于取代 t -> t 的场景）
        Function<Integer, Integer> identity = Function.identity();
        Integer apply = identity.apply(3);
        System.out.println(apply);

    }

}
